<template>
  <!-- 滚动通知 -->
  <view class="l-noticBar">
    <view class="marquee">
      <view class="marquee_box" id="marquee_box" :style="{height:noticeheight}">
        <view class="marquee_list" :class="{'marquee_top':animate}">
          <view class="marquee_View" v-for="(item,index) in listCopy" :key="index">
            <view>
              <text class="swiText">{{item}}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
  export default {
    props:{
      list:{
        type:Array,
        default:[]
      },
      // 展示条数
      showNum:{
        type:Number,
        default:1
      }
    },
    data(){
      return{
        noticeheight: '', //滚动模块高度
        animate: false, //是否滚动 
        listCopy:[...this.list]
      }
    },
    created() {
      //开始滚动
      let num = this.list.length > this.showNum ? this.showNum : this.list.length
      this.noticeheight = num * 100 + 'rpx'
      const timer = setInterval(() => {
        if (this.list.length < this.showNum) { //如果小于3条则不滚动
          clearInterval(timer)
          return
        }
        this.listCopy.push(this.listCopy[0]) //每次滚动在数组最后添加数组第一个元素 然后删除第一个
        this.animate = true
        const timer1 = setTimeout(() => {
          this.listCopy.shift()
          this.animate = false
          clearTimeout(timer1)
        }, 1000)
      }, 2000)
    },
    methods:{
    }
  }
</script>
<style>
  // 滚动区域
  .marquee {
    width: 100%;
    display: flex;
    /* position: absolute;
      bottom: 1rem;
      left: 0; */
  }
  
  .marquee_box {
    position: relative;
    width: 100%;
    overflow: hidden;
    display: flex;
  }
  
  .marquee_list {
    width: 100%;
    display: flex;
    flex-direction: column;
  }
  
  .marquee_top {
    transition: all 1s;
    margin-top: -98rpx;
  }
  
  .marquee_View {
    width: 100%;
    display: flex;
  }
  
  .marquee_View view {
    width: 100%;
    height: 85rpx;
    display: flex;
    flex-direction: row;
    margin: 15rpx 0 0 0; 
    padding: 10rpx;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-between;
    font-size: 24rpx;
    color: #fff;
    background-color: rgba(000, 000, 000, 0.5);
    border-radius: 10rpx;
  }
</style>
